package com.BinarySheep.eTools;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class eTools extends Activity {
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        // Hookup buttons to tool Activities
        Button button = (Button)findViewById(R.id.resistor);
        button.setOnClickListener(new OnClickListener() {
        	public void onClick(View v) {
        		// Launch resistor activity
        		startActivity(new Intent(eTools.this, Resistor.class));
        	}
        });
        
        button = (Button)findViewById(R.id.calcs);
        button.setOnClickListener(new OnClickListener() {
        	public void onClick(View v) {
        		// Launch Calcs activity
        		startActivity(new Intent(eTools.this, Calcs.class));        		
        	}
        });
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    	boolean result = super.onCreateOptionsMenu(menu);
    	MenuInflater inflater = getMenuInflater();
    	inflater.inflate(R.menu.menu, menu);
    	return result;
    }
    
    public boolean onOptionsItemSelected(MenuItem item) {
    	switch (item.getItemId()) {
    	case R.id.about:
    		showAbout();
    		return true;
    	case R.id.help:
    		showHelp();
    		return true;
    	}
    	return super.onOptionsItemSelected(item);
    }
    
    protected void showHelp() {
        View messageView = getLayoutInflater().inflate(R.layout.help, null, false);
        // When linking text, force to always use default color. This works
        // around a pressed color state bug.
        TextView textView = (TextView) messageView.findViewById(R.id.help_para1);
        int defaultColor = textView.getTextColors().getDefaultColor();
        textView.setTextColor(defaultColor);
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.help_title);
        builder.setView(messageView);
        builder.setPositiveButton("Done", null);
        builder.create();
        builder.show();
    }
    
    protected void showAbout() {
        View messageView = getLayoutInflater().inflate(R.layout.about, null, false);
        // When linking text, force to always use default color. This works
        // around a pressed color state bug.
        TextView textView = (TextView) messageView.findViewById(R.id.about_credits);
        int defaultColor = textView.getTextColors().getDefaultColor();
        textView.setTextColor(defaultColor);
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setIcon(R.drawable.icon);
        builder.setTitle(R.string.app_name_short);
        builder.setView(messageView);
        builder.setPositiveButton("Done", null);
        builder.create();
        builder.show();
    }
    
}